package com.shbaiche.bifenba.ui.home.sub;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.adapter.home.SubInfoAdapter;
import com.shbaiche.bifenba.kit.AppKit;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.video.ArticleVo;
import com.shbaiche.bifenba.net.JsonCallback;
import com.shbaiche.bifenba.net.NetApi;
import com.shbaiche.bifenba.ui.base.BasePagerFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.base.XLazyFragment;
import cn.droidlover.xrecyclerview.XRecyclerContentLayout;
import cn.droidlover.xrecyclerview.XRecyclerView;
import okhttp3.Call;

/**
 * Created by wanglei on 2016/12/10.
 */
@SuppressLint({"NewApi", "ValidFragment"})
public class SubInfoFragment extends XLazyFragment {

    SubInfoAdapter adapter;
    private List<ArticleVo> list;

    private int type = 1;

    @BindView(R.id.contentLayout)
    XRecyclerContentLayout contentLayout;

    protected static final int PAGE_SIZE = 10;
    protected static final int MAX_PAGE = 10;

    public SubInfoFragment(List<ArticleVo> list, int type) {
        super();
        this.list = list;
        this.type = type;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initAdapter();
    }

    private void initAdapter() {
        setLayoutManager(contentLayout.getRecyclerView());
        contentLayout.getRecyclerView()
                .setAdapter(getAdapter());
        contentLayout.getRecyclerView().setRefreshEnabled(false);
        contentLayout.getRecyclerView()
                .setOnRefreshAndLoadMoreListener(new XRecyclerView.OnRefreshAndLoadMoreListener() {
                    @Override
                    public void onRefresh() {
//                        loadData(1);
                    }

                    @Override
                    public void onLoadMore(int page) {
//                        loadData(page);
                    }
                });

        contentLayout.loadingView(View.inflate(getContext(), R.layout.view_loading, null));
        contentLayout.getRecyclerView().useDefLoadMoreView();
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_base_pager;
    }

    public SimpleRecAdapter getAdapter() {
        if (adapter == null) {
            adapter = new SubInfoAdapter(context, type);
            adapter.setData(list);
        }
        return adapter;
    }

    public void setLayoutManager(XRecyclerView recyclerView) {
        recyclerView.verticalLayoutManager(context);
        View v = new View(context);
        ViewGroup.LayoutParams pl = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AppKit.dp2px(context, 10));
        v.setLayoutParams(pl);
        v.setBackgroundColor(Color.parseColor("#FFF3F4F6"));

        recyclerView.addHeaderView(v);
    }
}
